package com.kitchen.ui.loading
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class ProcessLoading extends Sprite
	{
		private var proShape:Shape;
		private var tf:TextField;
		private var dw:Number, dh:Number;
		private var cmask:Shape;
		
		public function ProcessLoading(w:Number=100, h:Number=10)
		{
			super();
			this.dw = w;
			this.dh = h;
			var bg:Shape = new Shape();
			bg.graphics.lineStyle(2, 0xFF0000, 1);
			bg.graphics.beginFill(0xffffff, 1);
			bg.graphics.drawRoundRectComplex(0, 0, this.dw, this.dh, 10, 10, 10, 10);
			bg.graphics.endFill();
			this.addChild(bg);
			var load:Sprite = new Sprite();
			var sh:Shape = new Shape();
			sh.graphics.lineStyle(2, 0xffffff, 0.001);
			sh.graphics.beginFill(0x006699, 1);
			sh.graphics.drawRoundRectComplex(0, 0, this.dw, this.dh, 10, 10, 10, 10);
			sh.graphics.endFill();
			load.addChild(sh);
			cmask = new Shape();
			cmask.graphics.lineStyle(2, 0xffffff, 0.001);
			cmask.graphics.beginFill(0x006699, 1);
			cmask.graphics.drawRect(0, 0, this.dw, this.dh);
			cmask.graphics.endFill();
			cmask.x = -this.dw;
			load.mask = cmask;
			load.addChild(cmask);
			this.addChild(load);
			this.tf = new TextField();
			this.tf.x = this.dw+15;
			var tff:TextFormat = new TextFormat();
			tff.bold =true;
			tff.color = 0x000000;
			this.tf.defaultTextFormat = tff;
			this.tf.text = '0%';
			this.tf.autoSize = TextFieldAutoSize.LEFT;
			this.addChild(this.tf);
		}
		
		public function setProcess(rate:Number, title:String = ''):void{
			this.tf.text = Math.ceil(rate*100)+'% '+title;
			var cx:int = -Math.ceil((1-rate)*this.dw);
			//trace(cx);
			this.cmask.x = cx;
		}
	}
}